package com.we.wecc.aw.api.controller;

import com.we.wecc.aw.db.model.AwardComment;
import com.we.wecc.aw.mid.model.in.AwardCommentIn;
import com.we.wecc.aw.mid.model.out.AwardCommentOut;
import com.we.wecc.aw.mid.service.AwardCommentsService;
import com.we.wecc.bg.api.controller.BackController;
import com.x.share.db.model.Pagination;
import com.x.share.mid.exception.HelperException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(value = "评论接口")
@RestController
@RequestMapping("/wecc/awc")
public class AwardCommentController extends BackController{
    @Resource
    AwardCommentsService awardCommentsService;

    @ApiOperation(value = "获取评论信息列表", notes= "获取评论信息列表", response = AwardCommentOut.class)
    @RequestMapping(value = "/getAwardCommentList", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getAwardCommentList(
            @ApiParam(value = "云购期数id") @RequestParam("awardId") Integer awardId,
            @ApiParam(value = "当前页,默认第1页", defaultValue = "1") @RequestParam("pn") Integer pageNo,
            @ApiParam(value = "每页记录数", defaultValue = "10") @RequestParam("ps") Integer pageSize,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    )throws HelperException {
        Pagination<AwardCommentOut> page = awardCommentsService.getAwardCommentList(awardId,pageNo,pageSize);
        return success(page);
    }

    @ApiOperation(value = "根据parentId获取评论信息列表", notes= "根据parentId获取评论信息列表", response = AwardCommentOut.class)
    @RequestMapping(value = "/getAwardCommentListByParentId", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getAwardCommentList(
            @ApiParam(value = "云购期数id") @RequestParam("awardId") Integer awardId,
            @ApiParam(value = "回复当前评论的id") @RequestParam("parentId") Integer parentId,
            @ApiParam(value = "当前页,默认第1页", defaultValue = "1") @RequestParam("pn") Integer pageNo,
            @ApiParam(value = "每页记录数", defaultValue = "10") @RequestParam("ps") Integer pageSize,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    )throws HelperException {
        Pagination<AwardCommentOut> page = awardCommentsService.getAwardCommentListByParentId(awardId,parentId,pageNo,pageSize);
        return success(page);
    }

    @ApiOperation(value = "添加或修改评论信息", notes= "添加或修改评论信息", response = AwardComment.class)
    @RequestMapping(value = "/saveAwardComment", method = { RequestMethod.POST})
    public @ResponseBody Map<String, Object> saveAwardComment(
            @RequestBody AwardCommentIn in,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    ) throws HelperException {
        AwardComment awardComment = awardCommentsService.saveAwardComment(in);
        return success(awardComment);
    }

    @ApiOperation(value = "删除评论", notes= "删除评论", response = Boolean.class)
    @RequestMapping(value = "/deleteAwardComment", method = { RequestMethod.DELETE})
    public @ResponseBody Map<String, Object> deleteAwardComment(
            @ApiParam(value = "评论AwardCommentId") @RequestParam("awardCommentId") int awardCommentId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    ) throws HelperException {
        Boolean flag = awardCommentsService.deleteAwardComment(awardCommentId);
        return success(flag);
    }

    @ApiOperation(value = "点赞评论", notes= "点赞评论", response = Boolean.class)
    @RequestMapping(value = "/agreeAwardComment", method = { RequestMethod.POST})
    public @ResponseBody Map<String, Object> agreeAwardComment(
            @ApiParam(value = "评论AwardCommentId") @RequestParam("awardCommentId") int awardCommentId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    ) throws HelperException {
        Boolean flag = awardCommentsService.agreeAwardComment(awardCommentId);
        return success(flag);
    }

}
